I meant to make that change before I posted, but I guess I forgot. What can I say, it was 7am.

@OP

Even though that has 'fixed' your problem, you should ensure that your script isn't still making duplicate entries in your txt files. There may be bugs in your code that need to be fixed as well.

-genius_at_work