Possibly save 1 hour of your time: This actually happens when I copy the package file.
The Script Component id remains the same. Hence it was executing a previous package code. It is documented here by Microsoft:
One resolution mentioned there was to delete the script component and paste it again. It didn’t work for me. The id was still the same as before. You can see the id when you open in edit mode and it is near the top of the window.
The resolution for me is to recreate the script component. I just have to redo it unfortunately.