xmllint is a tool that uses libxml and comes with it. It's
--format option does what you want. All the work appears to be done by a library function
htmlSaveFileFormat. You could patch XML::LibXML to expose that function. You're not the first whose wanted a pretty print function from XML::LibXML.
Update: The simplest solution would be to add an optional format argument to $doc->toStringHTML and swap in htmlDocDumpMemoryFormat for htmlDocDumpMemory in that function.
Update: Never mind, htmlDocDumpMemory simply calls htmlDocDumpMemoryFormat with the format option set, and it doesn't help.