You should also try die ref $lightweight_fh to be sure it's not an object that stringifies to the filename. If it is not an object, it cannot use methods (->handle). If it is, you should read the documentation of its class to see what methods are supported. Seems like a bug in the CGI documentation?