Sorry for the slow response.
Suggest you review/study Ray L’s original example that you are using as a guide. It is very well documented so I will only try to elaborate on your changes.
Just put the #100 = 0.000 at the very beginning. Remember #100 is the name of a variable which contains a number and it can be used in your code the same as a number. But as a variable, that number can be changed. For example #100 = [#100 – 0.010] means ‘Let the new value of #100 be equal to it’s current value minus 0.010’. Thus you can see why it must have a current (starting) value and must be initialized before it can have a valid meaning and be used as a number.
You are correct to add a G0 Z1 in the sub to raise the tool to the safe height because you are returning to the start position directly (not retracing the cut path). The only problem is that the G0 Z1 is at the front of the loop so at the end of the last loop the depth is still at the final cut depth, (G1 Z#100 F16). The flow then returns to the line following the M98 P0001 L41 line which called the sub. This line (G1 X9 Y-3 F16) moves the tool directly back to the starting position at full depth which is what you were trying to avoid. So either move or add the G0 Z1 to the end of the loop (just before the M99) or insert it between the M98 line and the G1 X9 Y-3 F16 line. Or better yet, put it in all three places, doesn’t hurt anything and is probably the safest.
Hope this helps
Al