nMOSFET not turning off properly using RPi GPIO pins
Is the ground of the 12 volt supply connected to the RPi ground?

The MOSFET reacts to the voltage between its Gate and Source terminal - if the two grounds are not connected the Gate/Source voltage is undefined, and the Pi output cannot control the action of the MOSFET.