You need to change the section that offsets the parts - it looks to me to be a 3 x 4 array pattern that it is cutting. you have 3 positions in X 0, 50 and 100, and 4 posuitions in Y 0,40, 80 ,120
so where your while statements are you would need to put something like this (THis may not work as written, just looked at your code and then read the book) I would be more likely to use work offsets as there are some other advantages.
(position 1)
M98 P001
G10G91 L2 P1 X50. Y0. Z0.
M98 P001
G10G91 L2 P1 X50. Y0. Z0.
M98 P001
G10G91 L2 P1 X-100. Y40. Z0.G10G91 L2 P1 X50. Y0. Z0.
M98 P001
G10G91 L2 P1 X50. Y0. Z0.
M98 P001
G10G91 L2 P1 X-100. Y40. Z0.M98 P001
G10G91 L2 P1 X50. Y0. Z0.
M98 P001
G10G91 L2 P1 X50. Y0. Z0.
M98 P001
G10G91 L2 P1 X-100. Y40. Z0.
M98 P001
G10G91 LM98 P0012 P1 X0. Y-120. Z0.
END
and replace where (profile) is in the code
and stick an M99 whereright after the G0 Z10.0