Added file writing after the program is asked to exit.
removed printing of json data before writing to disk.