outfile = open(outfilename, 'w')
for line in open(infilename, 'r'):
    if line not in lines_seen:
        outfile.write(line)
lines_seen.add(line)
outfile.close()
How might I remove duplicate lines from a file?