Write config to specified config file.
Also fix errors in loading the config file by making it a global variable.