Every print ends with an error and the nozzle stopped on the print

Well I copied your endcode and the next two prints it actually had the hotend attempting to return to home. It at least didn’t leave the hotend touching the print, but it did still error out with these results


Ok, try this script

M104 S0 ; turn off extruder
M140 S0 ; turn off bed
M107
G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure
G91 ;relative positioning
G1 Z+0.5 E-5 ;X-20 Y-20 F{speed_travel} ;move Z up a bit and retract filament even more
G90 ; absolute positioning
G28 X0 ;Y0 ;move X/Y to min endstops, so the head is out of the way
G1 Y180 F2000
M300 P300 S4000
M84 ;steppers off