I fixed the write out to the file as well as pretty printing the result.