[Edited again to account for G.Myerson's answer and fan's comments]
It seems I can't delete even my own answers here, so I'm doing the next best thing:
Please ignore what I wrote in the first edit, ending with
In particular the answer to the question as posed is "no".
This assumes I computed what the proposer intended with the following gp code:
f(p, a) = sum(g=1,p-1,g*(a*g)%p)
That code is missing a pair of parentheses and should say
f(p, a) = sum(g=1,p-1,g*((a*g)%p)) a
With this correction, the answer is yes. Experimental evidence through $p=199$ is consistent with the conjecture f(a) \equiv p \frac{a+a'}{12} \bmod p^2 where a' is the multiplicative inverse of $a \bmod p$, which would imply that $f(a)\equiv f(b) \bmod p^2$ iff $a \equiv b$ or $a \equiv b^{-1} \bmod p$, as desired. In a previous edit I wrote at this point "I expect that (assuming I've not made yet another error) this corrected formula is known and/or not too hard to prove." This expectation was confirmed a few hours later by the original proposer, building on an answer from Gerry Myerson, who wrote $f(a)$ in terms of a Dedekind sum: $ f(a) = p^2 \bigl(s(a,p) + \frac14(p-1)\bigr). $ To calculate $f(a) \bmod p^2$, we may ignore the term $p^2(p-1)/4$; the result then follows from the reciprocity formula for Dedekind sums: $ s(a,p) + s(p,a) = \frac{a^2-3ap+p^2+1}{12ap} $ together with the observation that the denominator of $s(p,a)$ is not a multiple of $p$.