By adding NaOH you create magnesiumhydroxide (Mg(OH)2). This is a insoluble salt in water (just check the solubility tables of salts you can find anywhere on the web).
You don't mention which buffer system you use but such a subtle pH change can easily be achieved by changing the ratio of the acid and its conjugated base.
is your NaOH perhaps contaminated with phosphates? If I remember correctly, Mg-phosphates precipitate. However, this yellow color in your liquid is a bit strange.
I would try again starting from fresh MgCl2 but also fresh NaOH-solution. And make sure the glassware etc. is properly clean.