As said in the chat, if you need to modify the text dumped to the file adding some given **text**, probably you need to do it by hand:
open a file to write to, cycle on (sorted?) keys of such hash and print what you had to print to file.
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.