Keyboard shortcut to exit the print dialogue in safari
Normally, use the esc key.

This will dismiss the dialog without using the mouse.

This shortcut work with most dialog boxes in macOS.  See this answer for more details.

If one has remapped the esc key, using command+. should dismiss the dialog as well.  (Thanks to Steve Chambers' comment.)