Writes to file, and hashmap removes duplicates