in reply to removing duplicate lines

can also use the standard *nix tool uniq:
# assuming pre-sorted as in OP: uniq file1 > file2
As for your code's issue, try Data::Dumper to see what's different about the 'Name4' keys:
use Data::Dumper; print Dumper \%uniquelines;