I believe it's because you're sending the header Content-Disposition: inline, where it should probably be Content-Disposition: attachment if you click the download button, so the browser doesn't just show the file in the browser.
I did a quick test, and that seems to fix it.