Save history.json in the config folder

Previously, history.json was saved to the current working directory.
Now, generate.py uses the path to the folder for the config files
(passed in when the script is run) to save history.json.

Additionally, changed save_history() and get_history() to use `with
open(...) as file` so history.json is closed automatically even in case
of an exception.

Bug: T77936
Change-Id: I47c367b83ce89d3e3f23171f2485ff888939bacf