HTMLtidy or tidy
Koha uses HTML::Template with uses some new html tags that make tidy error
you can easilty create an ~/.tidyrc file containing this to tell tidy what to do with HTML::Template tags it finds in your *.tmpl file
new-blocklevel-tags: tmpl_loop tmpl_if tmpl_else tmpl_unless new-inline-tags: tmpl_var tmpl_include indent: auto indent-spaces: 1 vertical-space: n wrap: 0
then run
tidy -m ./foo.tmpl
and prepare to be beautified!