dedupe_file(path) that removes duplicate lines from a text file while preserving first-occurrence order, rewriting the same file, and returning how many duplicates were removed.dedupe_file('emails.txt') # a, b, a, c, b2
The second a and second b are removed; file keeps a, b, c.
Read all lines first; you cannot read and truncate simultaneously.
A seen-set plus an output list does the filtering.