Because Safari is a native application to macOS, you'll need to reinstall the entire operating system in order to delete and reinstall Safari. Before you do that, though, check for any updates in the App Store on your Mac. If all updates have been installed, try clearing your website data via these steps:
1. Open Safari, then click on Safari in the top menu bar and select Preferences.
2. Go to the Privacy pane and click on Manage Website Data.
3. Click on Remove All to clear all website data. This will log you out of any websites that you're automatically logged into.
If that still doesn't fix the issue, here's how to reinstall macOS without affecting your data or user accounts:
Method A: Use the App Store
1. Open the App Store and search for macOS High Sierra. Download the installer onto your Mac.
2. When the download is complete, the installer should automatically open. Make sure that the destination volume/disk is your startup disk (usually named Macintosh HD), then start the reinstallation. When everything is finished, you should end up either at the login window or at the desktop screen.
Method B: Use Recovery Mode or a bootable installer
1. Restart your Mac while holding down Command-R to boot Recovery Mode. Startup may be slower than usual. Alternatively, if you made a bootable installer for macOS High Sierra via these steps, plug in your bootable installer and restart your Mac while holding down the Option key. Use the arrow keys to select Install macOS High Sierra and hit Enter (Return).
2. When the Utilities menu appears, choose Reinstall macOS. Make sure that the destination volume/disk is your startup disk (usually named Macintosh HD), then start the reinstallation. When everything is finished, you should end up either at the login window or at the desktop screen.
Hope this helps!
EDIT: I just realized that your iMac may not be compatible with High Sierra. If this is the case, download and install the latest version of macOS or OS X that is available for your iMac.