CMD-Z reopens last tab instead of undoing

Most online text editors which support keyboard shortcuts (like the Stack Exchange editor right here!) support ⌃Z (ctrl-Z) for undo too, which won't cause any system functions to be fired.

If you want to use ⌘Z, you can remap the Undo Close Tab function off ⌘Z to something else using System Preferences → Keyboard → Shortcuts → App Shortcuts. Set Application to Safari.app, Menu Title to Undo Close Tab and Keyboard Shortcut to something other than ⌘Z.