The compass needle moved when the wire was connected to the battery. The important point here is that the needle is affected by the wire only when both ends of the wire are connected to the battery because only at this time is current flowing through the circuit.