Ensure all handles are closed before removal of file