HTML does not recognize carrige returns (or any other whitespace) for document spacing. You need the HTML tag for this purpose. Within your while loop, add the following line...
while ($filename = readdir(HOMEDIR)) {
print ("$filename\n");
print ("<br>\n");
}