Here's a Perl example. This isn't optimally compact, but this is more or less how I would write a script like this if I had to put it into production at $work (maybe with an extra check to make sure that exactly two command line arguments were provided).
use strict;
use warnings;
open my $read,"<",$ARGV[0] or die $!;
my @lines = <$read>;
close $read;
open my $write,">",$ARGV[1] or die $!;
print $write $line foreach my $line(sort @lines);
close $write;