When you output, you use the value of $k2 as a hash reference, but the second time through the inner loop, its value has been replaced by the key that each returned on the first time through. You need something more like this:
while ( my ($k1, $href) = each %hash ) {
while ( my ($k2, $k3) = each %{ $href } ) {
}
}
Incidentally, you use English without the important -no_match_vars option, and you use warnings as well as giving the -w, which is a bit redundant.
Also, your sample output is in the order that the lines were received, but you won't get your output in that order if you're using each and hashes for storage. There are ways of coping with that, but I can't tell if that's one of your requirements or not.