in reply to output the overlapping regions to new file
I don't know how big your files are, so I don't know how practical of a solution this will be, but you might try saving each sequence from each file as the key of a hash (set the value to 1), and then checking to see if the keys of one hash are present in the other, and if so, save those as the keys of a third hash, which then contains the sequences that are duplicated between the two files.