I can't reproduce that here. What does $! contain? See also the advice in "open" Best Practices.
In reply to Re: Failed to close file by haukex in thread Failed to close file by ovedpo15