Use temporary files during download

This prevents unfinished files from lying around when downloads are
interrupted.