Not had chance to look at the code yet.

However if you look at the picture it cocks up on opposite corners, assuming the picture is taken from the front of the machine then it barfs out when the Y changes direction so I'd check couplings, pulleys belts etc, anything to do with the Y axis mechanically