You can create multi-line strings by enclosing them in triple quotes. So you can store your HTML in a string and pass that string to write():
html_str = """
| Number |
Square |
<% for i in range(10): %>
| <%= i %> |
<%= i**2 %> |
"""
Html_file= open("filename","w")
Html_file.write(html_str)
Html_file.close()