The x and y coordinates in the table should be the vertices of the polyline, not the insertion point of the block.
The problem you were seeing was caused by the selection method and the cannoscale setting. The fence selection should pick the blocks in the correct order, but it picking up the K40 block in the wrong place and not filtering it because its insertion point is on the polyline. The quickest method to get round this is to temporarily set the cannoscale to 1:1m, make the selection then reset it. This of course all hinges on 1:1m being present as an annotative scale in all drawings.
This works well in my tests, but requires two regens of the current viewport (modelspace) which I have included. However this may slow down the lisp if you have a large drawing. The only other alternative that come immediately to mind is to make multiple selection set selections at every vertex and hope that the point in the centre of the block is found. This would require some sort of a re-write, but I have something that I may be able to adapt (when I can find it).
Attached is the revised lisp, I also found and re-corrected the problem of not starting at certain points.