Search for the duplicate in a textfile and store it in another textfile

I am new to coding and want some insights how can I find the duplicate in a text file and that duplicate will be store it to another text file.