If you disconnect the diode, you can see the effect of the magnetic field of the inductance causing high voltage peaks, when the switch is turned off. Because the energy of the magnetic field is not going to zero immediately, the inductance (a motor e.g.) is still pushing current into the transistor for a short time.
The transistor has a high restistance when it's turned off. High restistance x current of the load means high voltage.
The flyback diode is protecting the transistor from being destroyed, as you can see in the voltage curve.