in reply to Hash sorting

You need to print $key and the value associated with that key in %calhash.
print TESTFILE "$key;$calhash{$key}\n";
Also, $value will always be empty at that point as it has gone out of scope. If you find this sort of thing trips you up often, check out Dominus' comprehensive Coping with Scoping article.
HTH

broquaint