Keep same order of keys for ruby 1.8 and above

So input file has the same lines order as output
Fix expected output file for nil strings

Remove extra space add newline