Actually, if I understand your code, you can just

```perl
my $fh = CAF::FileWriter->new($pubcfg, log => $self);
print $fh ...;
my $rs = $fh->close();
if ($rs < 0) { die...; }
if ($rs > 0) {
    unless (rmtree...)
```