If the bank credits your account by mistake and you withdraw the funds they will come after you. This is probably the same thing.
On the other side of the coin why was this code tested on a live site and not testnet coins ?
This code was thoroughly tested using testnet.
The issue was with the server configuration, the database user did not have the proper permissions and the code failed in an unexpected way.
I have now changed to relevant code such that any failure of any kind will stop the script cold.