Handling duplicates in text files