Fixes #86 target file not closed before trying replacement