IMO you may find fault finding better if you:-
try to make just the sub as an incremental part, start with G91, end with G90, add up each address between those G codes separately... ie all the Z values must equal zero
... you can then introduce the X step.... suggest you put at the start of sub.... the XYZ start point should allow for the X step.
Programming entirely in incremental can lead to a large problem, you've got a lot more to check.