Move call to write_config() so as not to invalidate the loop iterator.