Fixed code by providing file handle