<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_config(data, conf_dir=DEFAULT_CONFIG_DIR, codec="yaml", backup_existing=False):
 """ Write config values to a file. Arguments: - conf_dir<str>: path to output directory - codec<str>: output field format - backup_existing<bool>: if a config file exists, make a copy before overwriting """

    if not codec:
        codec = 'yaml'
    codec = munge.get_codec(codec)()
    conf_dir = os.path.expanduser(conf_dir)
    if not os.path.exists(conf_dir):
        os.mkdir(conf_dir)

    # Check for existing file, back up if necessary
    outpath = os.path.join(conf_dir, 'config.' + codec.extensions[0])
    if backup_existing and os.path.exists(outpath):
        os.rename(outpath, outpath + '.bak')
    codec.dump(data, open(outpath, 'w'))