You have several questions all put together and your definitions of what you want for each of them is not fully defined.
Given these issues let's start with the challenge of getting duplicate lines from one file into another file.
This simple little bit of Python should work for you.
""" Write duplicate lines in one file to a text file. """
fileToRead = 'read_file.txt'
fileToWrite = 'write_file.txt'
dupLineSet = set()
with open(fileToRead, mode='r') as read_file:
file_lines = read_file.readlines()
file_lines_copy = file_lines
for line in file_lines:
matches = 0
for line_copy in reversed(file_lines_copy):
if line == line_copy:
file_lines_copy.remove(line_copy)
matches += 1
if matches > 1:
if line.strip() != '':
dupLineSet.add(line)
with open(fileToWrite, mode='w') as write_file:
for line in dupLineSet:
write_file.write(line)
##############################
NOTE:
Give it a run and see if you like the outcomes.
Since you have not defined what a 'duplicate' means I have made some assumptions you may not like.
Anyway drop the above into ST, edit the bits you need to and use Tools -> Build
to run the code.
Look at the output file and tell us how it is not like what you want.
Once we have an agreed output for a single file getting you a version that works on two files is the next big challenge.