Remove output headers when `--print-only` is requested

cherry picked from commit 3cf27313755be21a909b55554dbf13589aadb498