Create a folder named TargetSound in your AddOns directory. Put TargetSound.toc and TargetSound.lua into the TargetSound folder.
Edit: To elaborate, WoW recognizes addons by scanning the AddOns directory. Any folder containing a .toc file of the same name indicates an addon. The .toc file is the Table Of Contents; it tells WoW what files actually contain the addon. In this case, TargetSound.toc tells WoW to look in the TargetSound.lua file for the addon, although the .lua file could actually be named anything, as long as the .toc file referenced it. Addons can be contained in a single file, like this one, or spread over multiple files, like PitBull. Addon files can either be Lua script files (*.lua) or XML files (*.xml). The scripts contained in the Lua or XML files can reference additional media files, such as images (*.tga or *.blp) or sounds (at least *.wav and *.mp3, and I'm not sure if WoW recognizes any others). At a bare minimum, in order for WoW to recognize an addon, it needs a folder containing a .toc file with the same name as the folder (case sensitive) and at least one Lua or XML file.
Create a new folder in your AddOns directory and name it TargetSound. Put the following files into the TargetSound folder:
## Interface: 20300
## Title: TargetSound
## Notes: Plays a sound upon gaining or losing a target.
local f = CreateFrame("Frame")
if UnitExists("target") then
if UnitIsEnemy("target", "player") then
elseif UnitIsFriend("player", "target") then
Will work with any unitframe addon (or even with no unit frames at all), and won't require you to edit addon files every time the addon is updated.