I tried the above posted script and do not get any compile errors.
However there are a couple of problems in its operation.
The first is that if you have G04 dwell time set to seconds in General Config, (the default setting) then 5000 seconds is too long to wait. My coffee would go cold while I waited.
And if you have it set to MS, then the other G04 delays are so short as to be irrelevant. Something like Sleep 100 would be more appropriate.
The other issue is, if a user started this script with Z axis DRO at say -6, then the first move will be in an unexpected direction.
I really hate it when a CNC machine I am operating does something I do not expect.

Either zero the Z axis DRO prior to the G31, or do G91 G31 Z-5 probe move.
Greg