The current carrying wire produces magnetic field around it. When a compass is kept nearby this wire, the two magnetic field (magnetic field due to wire and magnetic field due to compass) interact each other causing deflection in magnetic needle. When the current is switched off, there is no magnetic field produced by the wire, magnetic needle does not deflect from its north-south position.