Well I would pass on the E39 M5...I came from one and I sincerely loved it. The e39 is my favorite BMW body. With that being said, the maintenance and mod cost on them is far greater than what makes the performance justifiable (for me anyway)
Cars are just getting so fast these days, the e39 M is long in the tooth.
As far as modding the 335i, that's why I bought mine. With relatively cheap mods (and easy as bolt ons) you get a totally different beast.
I'd say start with a tune (you can research which one you want, as to avoid the wars) I would hold out on the mufflers...they don't do much for performance
On my M5 it was the same with mufflers...high dollar, no performance gains. I just put a pair of magnaflows on and had the cats cut out...great sound and it was cheap.
All and all...its a great problem to be faced with