Safari automatically opens downloaded files it considers as Safe. It may include compressed files, PDF, pictures, videos, and other type of files downloaded from trusted sources. But sometimes, the so-called safe files may contain viruses or malware.
You might want to turn off this feature (enabled by default) for your own good. It can be done from Safari's preferences or through a simple terminal command.
Turn Off "Auto Open Safe Download" in Safari
Launch Safari, click on the Safari menu > Preferences. Go to the General tab and clear the Open "safe" files after downloading checkbox.
Turn Off "Auto Open Safe Download" from the Terminal
To turn off the auto-open function from the terminal, simply open a terminal and run the following command:
defaults write com.apple.Safari AutoOpenSafeDownloads -boolean NO