core: Be more paranoid when writing config files