If htmldoc works from the command line but not using the code above then there must be something specific to your system. As it's working for me I am not sure what else to suggest as the code seems valid. Anything that would cause it to fail should output to your logs.
Check the module documentation to see if it has any debugging options or bug reports for this issue. I believe it does have an error function for reporting errors it encountered. You could try running the example script from the command line rather than as a cgi. If you are confident with strace usage strace the script as it runs to look for missing files or permissions problems which are not getting logged.