By the way, I used chatgpt to generate that code. I had to prompt it with multiple corrections.
It did not have any safe Z move to start with
It did not go back to X0Y0 between Z passes, so would have ended up out of limits / moving further and further in X and Y
(The point being that it is worth having some understanding of Gcode)
AI can generate code but dont blindly trust the output. This applies for other languages for AI. It can be a good starting point but often has issues requiring additional prompts