Sorry to hear that.
Thermostat are fairly common failure, mine went. Followed by the water pump a week or so later. Have you any idea how old the cooling system is? Recommendation is to replace the lot roughly every 60k/5 years. If you don't you end up with it failing one item at a time and multiple tow truck trip to the shop/home. With these car you do need to factor in a reasonable amount of money for maintenance that you wouldn't need to on most other cars (e.g. cooling system). I think they were designed by German's for German's, so they expect to be maintained in a German style....
An e39 is like a beautiful wife, needs constant attention, lots of money, lets you down at the worse times but you’d never be without it.