in reply to Failed to close file

Use three argument open, let perl tell you why this failed, $!.