path: extend write to work with functions that can write to a file, to handle atomicity