As an aside, that snippet works in 5.6.1, and as far as I know, worked with much earlier versions too. What was introduced in in 5.8.0 was the ability to use a reference for the filename as an alternative to IO::Scalar.
Comment on Re: Catching errors in closing lexical filehandles