The problem you are having is simply a matter of IE adding widths differently than the other browsers. The reason it looks right for a moment, but then goes all wacky on you is because it is correct until the scrollbar appears on the right side of the browser. That scroll bar shrinks the width of the viewport just enough to push everything out of place.
Subtract a few pixels from the width of each item for your IE 5 style sheet.
BTW - Stop using PHP to try to sniff browsers.
Use the built in capabilities of IE to do that for you. The advantage of doing it that way is, you can still use your standard stylesheet for everything, you only have to "fix" the "broken" rules in your additional stylesheets.