The main problem is that you store the AA
records in an array called @{$record{'AA'}{trs}}
(i.e. @{$record{'AA'}->{'trs'}}
), but when you go to print those records, you don't iterate over that array, you just try to read it as a scalar.
The fact that your file is tab-delimited does not seem to be relevant, since you apparently consider two lines to be distinct if either record is different. So you don't need to worry about the complexity of converting your lines to "records" for processing.
(Even aside from that, you have a lot of unnecessary code — for example, there's no reason at all to create $ref
.)
You can actually just dispense with Perl, and use the standard sort
utility:
sort -u <INPUT_FILE >OUTPUT_FILE