Added write_config and its tests.