Avoid printing Caveats title when output is empty

Closes #4878
Merge pull request #5806 from federicobond/conditional-caveats

Avoid printing Caveats title when output is empty