Script sometimes creates an empty file

I have a script that runs ditto for me, and occasionally (if I exit the script while ditto is running in the background) it will leave an empty file named 0 in the script's directory. The next time I run the script, it generates incorrect data because of this file. I know I can easily insert a check for this file and delete it, but does anyone know what this is and why it happens?

Thanks.

Don't you think it would be helpful to display the script?

---------- Post updated at 11:04 AM ---------- Previous update was at 10:41 AM ----------

Please do not double post: