LM339: why is the output +5V
Well, the LM339 is a comparator, not an op-amp. It is intended to compare the two input voltages and put out one of two levels depending on the result of the comparison.  It is not intended to be used with feedback, except possibly positive feedback for hysteresis.  The output is an open collector, and there is a pull-up to 5V, meaning that when the non-inverting input is higher than the inverting input the output transistor is OFF, and the output will go to whatever voltage the pull-up (Rp) is connected to.