Ok, I think I know the reason of why my car had a shimmy. I am posting this to help other BMW drivers in case they have the same problem.
My car was in an accident and I decided to replace it than repair it. So I took an E39 to Mechanic 2 for a pre-purchase inspection. The car was in a very good condition mechanically and cosmetically (inside and out), but it had a shimmy at 120km when the mechanic and I test drove it. It was the same shimmy my old E39 had: I felt it in the floor of the car. Mechanic 2 told me that he is 99.9% sure it is the tires. So I went back to the dealer and told him about the shimmy and he swapped the summer tires with winter tires and we went for a test drive, and sure enough the shimmy was gone.
This is kind of sad because the tires I had on my old E39 were new Yokohama TRZ tires, that were recommended and installed by another mechanic (Mechanic 1). I spent hundreds of dollars on new tires that shimmy! To solve the problem of the shimmy Mechanic 1 said I needed a new driver-side drive shaft which cost me $420 and solved nothing. (Afterwards, he even dared to suggest I needed a passenger-side drive shaft!) Anyway, I stopped going to Mechanic 1.
In conclusion: if you have the same shimmy problem, try to swap your tires to eliminate them as the source of the shimmy before you let any mechanic replace parts that are not broken and waste your time and money.