I have tweaked your code and this works for me. Remember to use strict and warnings especially important if you have an error but nothing is appearing in the logs. For delivering a pdf to a browser you need a content type header.
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
my $cgi=new CGI;
print $cgi->header( -type => 'application/pdf' );
use HTML::HTMLDoc;
my $htmldoc = new HTML::HTMLDoc();
$htmldoc->set_html_content('<html><body>A PDF file</body></html>');
my $pdf = $htmldoc->generate_pdf();
print $pdf->to_string();
$pdf->to_file('newpdfdoc.pdf');