Why do we need a resistor here?
This circuit is supposed to act like an OR gate. You need the resistor for the diodes to work correctly, especially in the off state.

$$\begin{array}{|c|c|c|c|}
\hline
\rm A &amp; \rm B &amp; \rm D1 &amp; \rm D2 &amp; \rm Out \\ \hline
0 &amp; 0 &amp; \rm off &amp; \rm off &amp; 0 \\ \hline
0 &amp; 1 &amp; \rm off &amp; \rm on &amp; 1 \\ \hline
1 &amp; 0 &amp; \rm on &amp; \rm off &amp; 1 \\ \hline
1 &amp; 1 &amp; \rm on &amp; \rm on &amp; 1 \\ \hline
\end{array}
$$

When A and B are both zero, D1 and D2 are both off. Without the resistor, the output node would float, meaning it would be affected by nearby electric fields and static electricity. In general, you should always have a DC path to ground for every node in your circuit.