Command-W not working correctly on Safari
Go to your System Preferences… application, and select the Keyboard pane.

Hit the Keyboard Shortcuts tab on top, and Application Shortcuts on the left. Is there an entry for Close Tab ⌘W or an entry for Close Window that's set to something else? If so, remove it with the +- widgets at the bottom of the window.

Without knowing what other applications you're running, that's the first place I can think of to check what might be intercepting it.