In functional style, but still in Python (given that python method calls are equivalent to function calls with an additional first argument of the receiver object, and indexing is equivalent to a method call) -- this uses mutable objects, but doesn't actually rely on mutating them:
addEmail = lambda |doms,email| doms.union([email.split("@")[1]])
domains = reduce(set(),addEmail,open("file_with_emails.txt","r")))
open("file_with_domains.txt","w").writelines(domains)
(Loses order because of use of set for deduplication; you could do it with a list and keep order, but then addEmail becomes more complex, and I don't think its strictly necessary to illustrate the general process. Also, its not clear to me that order-preservation is really part of the intended function here or just an artifact of the implementation. Note that this could be a one-liner, its just split up into three lines with two as assignments for readability.)And, more how I'd really write it in Python (which is also functional, though perhaps less obviously so, and leverages Python set comprehensions):
domains = { email.split("@")[1] for email in open("file_with_emails.txt","r") }
open("file_with_domains.txt","w").writelines(domains)