Write $D = D_1 - D_2$ with $D_1, D_2$ effective. By Riemann–Roch, we have $$\chi(X,\mathcal O(D_i)) = \int_X \operatorname{ch}(\mathcal O(D_i)) \cdot \operatorname{td}(T_X).$$$$\chi(X,\mathcal O(D)) = \int_X \operatorname{ch}(\mathcal O(D)) \cdot \operatorname{td}(T_X),$$ Theand similarly for $\mathcal O$. The point is that the right hand side is defined purely in terms of intrinsic geometry of $X$ and the intersection behaviour of $D_i$$D$. Indeed, for a line bundle $\mathcal L$, we have $$\operatorname{ch}(\mathcal L) = 1 + c_1(\mathcal L) + \frac{c_1(\mathcal L)^2}{2} + \ldots + \frac{c_1(\mathcal L)^n}{n!};$$ we cup it with some fixed thing $\operatorname{td}(T_X)$, and we integrate (i.e. take the degree of the component in dimension $0$). This only depends on the intersection behaviour of $c_1(\mathcal L)$. We conclude that $$\chi(X,\mathcal O(D_1)) = \chi(X,\mathcal O(D_2)),$$$$\chi(X,\mathcal O(D)) = \chi(X,\mathcal O),$$ since the intersections of $D_1$$D$ and $D_2$$0$ with any curve agree.
IfEdit: An argument is missing here; I thought I fixed it but that created a different gap. In order to deploy the theory of Quot schemes, we have to write $H$$\mathcal O$ and $\mathcal O(D)$ as quotient of the same vector bundle. For this, some boundedness argument is ampleneeded. This is carried out in characteristic $0$ in Lazarsfeld's Positivity in Algebraic Geometry I, replacing $D_i$ byProp 1.4.37 $-D_i + nH$ and using additivity(using Fujita's vanishing theorem), or in exact sequencesgeneral in FGA Explained, we similarly get $$\chi(X,\mathcal O_{D_1}(nH)) = \chi(X,\mathcal O_{D_2}(nH)),$$ soLemma 9.6.6 (using a variant of Mumford's argument for boundedness of the Hilbert polynomials ofscheme, cf. $D_1$ andLectures on curves on an algebraic surface, Lecture 14, $D_2$ agreeTheorem).
WhenNow by the theory of Quot schemes, when we fix the Hilbert polynomial, the HilbertQuot scheme is projective. In particular, it has finitely many components, so a multiple of $D_i$$\mathcal O(D)$ has to land in the identity component $\operatorname{Pic}^0_{X/k}$. Choose
Now write $n$ such that$D = D_1 - D_2$ with $nD_i \in \operatorname{Pic}^0_{X/k}$ for$D_1, D_2$ effective; then $i \in \{1,2\}$$D_1$ and (it actually suffices that they land$D_2$ lie in the same component; not necessarily the identity component) of the Picard scheme. Choosing a curve connecting these two points in $\operatorname{Pic}^0_{X/k}$ gives a family of effective divisors from $nD_1$ to $nD_2$, showing that $nD \sim_{\text{alg}} 0$. $\square$