Whats this wire for?

Hey, recently traded my lawnmower for a 2003 Kodiak and slowly getting some of the wiring cleaned up.

I have only 2 wires coming off my taillight so i assume this is not the origonal light. the wires are blue and black. i also have 2 wires on the bike blue and black so i assume those go together. and there is also a yellow wire and that must be for the brake light but it is not attached to anything. now i have another black wire that is connected the ground wire on the motor side that has the same connections but i have nothing for it to connect to.

The bike runs great and seems to work good untill i turn the headlights on and they are very bright but pulsate/flicker.

Thanks for the help