split print function and fix some return codes
this makes the code a little bit more readable
and avoids an ugly goto to skip printing the table.
Also don't return errno if the output file already
exists because access() doesn't actually set
it when it returned 0.