add monkey patch to write file only after commit

This ensure a file is never created on filesystem while transaction will restart.

This former behavior was creating multiple times the same file on serialized error.
you need some error handling here, and a test to see what happens if an exception is raised by one of the actions.