or download this
# note that part of your trouble could be your antiquated file-handle
+representation (doubtful).
open my $output_file, ">", "ki_file.txt" or die $!;
# unpack can be a little arcane...
print $output_file unpack("H*", $ki_token), "\n";