What is this for and is it needed?

It's a little tough to see in the pics, but it looks like a brake proportioning valve. If it has wires coming from it those are likely for a line lock.

And yes it is needed or your rear wheels will lock up when you brake.