A bulb with a 12 V 50 W rating is designed to have a resistance of 122/50 = 2.88 Ω when in operation (P=V2/R). Similarly, a bulb rated at 12 V 35 W rating is designed to have an operating resistance of 122/35 = 4.11 Ω. The point to note is that a 50 W bulb has a smaller resistance than a 35 W bulb.
At first both bulbs were individually connected across a 6 V battery. Since the potential differences across both bulbs were the same, to compare the power dissipated in the two bulbs, we should think V2/R. So the 50 W bulb, with a smaller resistance, shone brighter.
Later the bulbs were connected in series across a 12 V battery. Since the current flowing through both bulbs was the same, to compare the power dissipated in the two bulbs, we should think I2R. So the 35 W bulb, with larger resistance, shone brighter.
(Do note that when connected in series, the potential difference across each bulb was no longer 6 V each. By the potential divider principle, the 35 W bulb, with its larger resistance, ended up with more than 6 V of potential difference across, while the 50 W bulb had less than 6 V across)