Fix removing file when replaceFile method is used