The battery light on the dashboard (when on) shows that the battery voltage is higher than the charging voltage and that the battery is not being charged.
If forms part of the circuit to the exciter windings of the alternator - it the wire come loose or the bulb fails there will no current to the field windings of the alternator - the battery will not charge and eventually run flat. The light will remain off and you will not know until the battery goes flat.
If the light remains on it shows a low voltage from the alternator - the fact that that it sometimes works suggests that the alternator itself is not defective.
I am not a motor engineer but I would suspect that sometimes the alternator is not being driven fast enough to make the light go out. I guess a slack or slipping drive belt.
The battery is not going flat because some of the time there is enough charging voltage to top it up when the light is out.
I am not in any way qualified to offer this opinion.
Good Luck...
February 2016