When we are running script first time script running properly but next time system
First time script running successful but next time getting error file got corrupted.
Start your test with a clean-up. For me it is a best practise to set the state of the environment under test. This might mean deleting some files or database records.
Now it could be a defect, if you expect the same script to be runnable over and over again.