perlなら「書く」というレベルじゃない。コマンドラインで実行して使い捨て。

perl -ne 'print join(" ", sort(split(/\s+/))), "\n"'