Save the download with .download extension first and rename it to the file upon successful completion.

This change helps avoid incomplete downloads.