write_to_file prevents duplicate lines being written