Very simple. First, make sure you consolidate the library. Do this by checking the "copy music to my itunes folder" box checked in the preferences and then go to file->library->consolidate.
After consolidating the library, just copy the entire iTunes folder onto your external. It is in /Users/<username>/Music/.
After reformatting, open iTunes the first time so it creates a library but then close it. Then just copy your iTunes folder backup overtop of the iTunes folder on the new system.