first collect all data to write into variable 'htmlOutput' and then write it in one bunch into the html file with the 'innerHtml' method