d = {}
for line in open('a.txt'):
d[line] = d.get(line, 0) + 1
fd = open('b.txt', 'w')
for k, v in d.items():
if v > 1:
fd.write(k)
fd.close()
d = {}
for line in open('a.txt'):
d[line] = d.get(line, 0) + 1
fd = open('b.txt', 'w')
for k, v in d.items():
if v > 1:
fd.write(k)
fd.close()