I believe the term Passive and PWM have been misleading. This circuit should protect the MOSFET from your input experimentation.
Use almost any enhancement mode N-channel MOSFET in a TO220 case. It needs to be rated at 30V or better. Like the power diode above it, the MOSFET need only carry the electromagnet current.
When the switch turns off, a positive voltage spike from the inductance of the electromagnet is clamped by the power diode across the magnet coil. The diode prevents the flyback spike from destroying the MOSFET.
The MOSFET should be turned fully on or fully off. Then there will be either low voltage across it, or low current through it, so there will be low V*A = low power dissipated in the MOSFET. A heatsink should not be needed, check it does not get hot in use.
In order to safely control the MOSFET gate you must convert a slowly changing analog voltage into a digital signal that has sufficient current available to drive the MOSFET gate quickly through it's transition zone. That circuit is called a schmitt-trigger.
The LM555 is a very common 8 pin timer IC, but it is being used here only as a simple schmitt-trigger. The input thresholds are at Vcc/3 and Vcc*2/3. For Vcc=12V, when the input voltage on pin 6 rises above 8V the output goes low and the MOSFET turns off. When the input voltage on pin 2 falls below 4V the output goes high, turning on the MOSFET and electromagnet. The input impedance of pins 2 and 6 is high, so easy to drive.
The 47 ohm resistor limits the transition current from the LM555 into the gate capacitance of the MOSFET when switching. It also prevents parasitic oscillations of the gate structure.
The two 0.1uF ceramic bypass capacitors are there to keep switching spikes out of the system when used with long cables or a tired battery.
Start with say a 10k or 100k potentiometer on the input. Check the thresholds are 1/3 and 2/3 of Vcc. Then insert the MOSFET and check the electromagnet is controlled by the pot.
Next you can experiment with a photo-interrupter. Connect the detector between + and in, and a resistor of say 22k between in and -. That makes a voltage divider to replace the potentiometer you used during testing. You will need a light source, maybe powered between B+ and B- through a series resistor, try 470 ohms if it is a LED.