in reply to Find duplicate lines from the file and write it into new file.

to check if a line has been seen before you need to remember all lines you read somehow.

but first you could just post the code you tried out here because people don't want to post answers only to see that your code already did that.

an untested trial from me would be: perl -pi -e' $_ = "" if $seen{$_}++' file
of course the hash %seen will get quite big (unless you have very much duplicated).

edit: oops, you want to print out the duplicates.
perl -ne' print if $seen{$_}++ == 1; ' file > newfile