def METHOD_NAME(path, new):
    if os.path.exists(path):
        with open(path, 'r') as fp:
            old = fp.read()
        if new != old:
            with open(path, 'w') as fp:
                fp.write(new)
    else:
        with open(path, 'w') as fp:
            fp.write(new)