If you use the end g-code from the screenshot (sorry it's so small, not sure why), make sure you do not use G1 X0 Y0 Z5 but rather put G1 Z5 on a separate line after G1 X0 Y0.