Also, I noticed a bug with your script,
if the item already has a loop region,
and that you use the script to write a marker BEFORE that region,
then the region-marker destinction of that marker is messed up,
Look how the BUG marker become a loop poin in item whil the Green loop in item become a marker.
My guess is that is determined by marker ID in the smpl chunk, which isn't touched by your script so can lead to error if the items has loop points.