So the original script did not crash, but the copied script crashes?

Then either there is still a difference between both scripts, or the crash is random. Random crashes can be by an uninitialized variable or by accessing past a series or array length. But that's mere speculation. You need to systematically debug that script.