Improve download file.

Added check to wroteToFile