As a follow up this looks like it could just be a browser or a machine issue. I am running a Macbook pro and the file downloaded fine while running Safari. But failed in Firefox, chrome and MS Edge.
It looks like there were two issues at play here. The time complexity in the nested for loop. At around 150k iterations Chrome started to fire off alerts to the user about killing an unresponsive page. Note that Safari did not and handled the operation.
Two Chrome limits the size of a download that can be attached to a tag to 2 MB.
https://stackoverflow.com/questions/38781968/problems-downloading-big-filemax-15-mb-on-google-chrome