in reply to Getting from Oracle to become a text file

print $newfile;
It helps if you print to the open filehandle:
print BATCH $newfile;
BTW, you are not checking the status of your connect or any other DBI statement. The simple thing to do would be to take a look at RaiseError in the DBI docs and use it in the connect statement.