You are trying to prove the second mean value theorem for integrals under very weak assumptions. If you have stronger conditions like continuity or differentiability, there are easier proofs. In fact, if you know that $f$ is non-negative then you can conclude immediately since $g(x)$ is between $g(a)$ and $g(b)$ and $\int_a^b f \geqslant 0$ which implies that $\int_a^b fg $ is between $g(a)\int_a^b f$ and $g(b)\int_a^b f$.
I can provide a very general proof given your hypotheses. Suppose that $g$ is non-decreasing (a similar argument applies if $g$ is non-increasing). Then $h(x) = g(x) - g(a)$ is non-decreasing and non-negative.
We have the following lemma:
Suppose $f$ is Riemann integrable and $h$ is non-decreasing and
non-negative. Let $F(x) = \int_x^b f$. If $A \leqslant F(x) \leqslant
B$ for all $x \in [a,b],$ then $h(b)A \leqslant \int_a^b f h \leqslant
h(b)B$.
Since $F$ is continuous, finite bounds $A = \inf_{x \in [a,b]} F(x)$ and $B = \sup_{x \in [a,b]} F(x)$ exist and by the IVT there exists $\xi \in (a,b)$ such that
$$\int_a^bf h = h(b) \int_\xi^bf$$.
Thus,
$$\int_a^b fg - g(a)\int_a^b f= \int_a^bfh = h(b) \int_\xi^bf = g(b)\int_\xi^bf - g(a) \int_\xi^bf$$.
Adding $g(a)\int_a^bf$ to both sides we get
$$\int_a^b fg = g(b)\int_\xi^bf - g(a)\int_\xi^b + \, g(a)\int_a^bf = g(b)\int_\xi^bf + g(a)\int_a^\xi. $$
It remains to prove the lemma. This can be done using an argument based on Riemann sums.
Taking any partition $P = (x_0,x_1, \ldots, x_n)$ consider the Riemann sums
$$S_P = \sum_{k=1}^n f(x_k) h(x_k)(x_k -x_{k-1}), \\ S_{P,j} = \sum_{k = j}^n f(x_k)(x_k - x_{k-1}),$$
which converge to $\int_a^b fh $ and $\int_{x_{j-1}}^b f$.
Since $f(x_k)(x_k - x_{k-1}) = S_{P,k} - S_{P,k+1}$ we have
$$S_P = \sum_{k=1}^n h(x_k)(S_{P,k} - S_{P,k+1}) \\ = h(x_1)S_{P,1} + (h(x_2) - h(x_1))S_{P,2} + \ldots (h(x_n) - h(x_{n-1}))S_{P,n} $$
Let $\hat{A}$ and $\hat{B}$ be the upper and lower bounds for the finite set $\{S_{P,k}\}$. Since $h$ is non-decreasing $h(x_k) - h(x_{k-1}) \geqslant 0$ and
$$\tag{1}\hat{A} h(b) = \hat{A} h(x_n) \leqslant S_P \leqslant \hat{B} h(x_n) = \hat{B} h(b).$$
As the partition is refined, the sum $S_P$ converges to $\int_a^b fh $ and it can be shown that $\hat{A} \to A$ and $\hat{B} \to B.$
For any $\epsilon > 0$, we can find a sufficiently fine partition $P$ such that
$$\tag{2}S_P - \epsilon < \int_a^b fh < S_P + \epsilon,$$
and for all $j$,
$$\tag{3}\int_{x_{j-1}}^b f - \epsilon < S_{P,j} < \int_{x_{j-1}}^b f + \epsilon .$$
Now (1) and (2) imply
$$\tag{4} \hat{A}h(b) - \epsilon < \int_a^b fh < \hat{B}h(b) + \epsilon.$$
Since,
$$A = \inf_{x \in [a,b]}\int_x^b f \leqslant \hat{A} \leqslant \int_{x_{j-1}}^b f \leqslant \hat{B} \leqslant \sup_{x \in [a,b]}\int_x^b f = B,$$
we have $A - \epsilon \leqslant \hat{A} - \epsilon$ and $\hat{B} + \epsilon \leqslant B + \epsilon,$ which along with (4) implies that
$$(A - \epsilon) h(b) - \epsilon < \int_a^bfh < (B + \epsilon) h(b) + \epsilon,$$
and
$$\tag{5}Ah(b) - [1 + h(b)]\epsilon < \int_a^b fh < B h(b) + [1 + h(b)] \epsilon.$$
Therefore, since $\epsilon > 0$ can be arbitrarily small,
$$h(b)A \leqslant \int_a^b f h \leqslant h(b)B.$$