I have something that works great in batch:
DNAME = "WTSO.WNEG.DBA.DBDTEXT("||MEM_NAME||")"
"ALLOC DA('"DNAME"') F(STATOUT) SHR"
"EXECIO * DISKW STATOUT (FINIS"
I just build my lines and queue them, then call this procedure. The empty QUEUE statement lets the EXECIO do a clean write.
I run this from TSO, never tried it in batch. Of course the PDS has to be defined already.