Zero-byte files exist

This file got created regardless of perl’s output:

perl some-script.pl > file.txt

rem always true
if exists file.txt (
...
)

The batch script continues since the file always exists, even if there is no content. So instead I used

for /f "tokens=3" %%i in ('dir /-C file.txt') do (
  if %%i==0 (
    echo error
    exit /b 1
  )
)