You say mirror but don't you mean the window glass?
There is a separate circuit to power the windows with the ingition off and the door open. Since the window seems to work fine when this circuit is active, this suggests that there is a poor connection on the normal ignition controlled circuit. This could be a corroded connector, a chafed wire or a dodgy fuse. I'd check the fuse first, and replace it even if it looks OK since they can deteriorate and this is easy and cheap to do.