I've created an extension for Safari which does exactly what you want. It closes all the tabs except for the tab that is currently active.
As a side effect you can also change a setting which when enabled will on pressing the button ask you if you really want that (to prevent accidental...