I believe this is well-known to those working in regular/inverse semigroups. So well-known in fact that one can even find proofs on the web, e.g. see this proof on PlanetMath. Alas, I cannot recall the history of this result, though I vaguely recall reading something about such decades ago. For completeness, I reproduce below said common proof (slightly edited).
Theorem $\ $ A non-empty semigroup $\,S\,$ is a group if and only if for every $\,x\in S$ there is a unique $y\in S$ such that $\,xyx=x$.
Proof $\ (\Leftarrow)\,$ For each $\,x\in S\,$ let $\,x'$ be the unique element of $\,S\,$ such that $\,xx'x=x.\ $ Note $\,x(\color{#0a0}{x'xx'})x=(xx'x)x'x=x\color{#C00}{x'}x=x,\,$ so, by uniqueness, $\,\color{#0a0}{x'xx'}=\color{#C00}{x}',\,$ hence $\,\color{#0a0}x = \color{#C00}{x}''.$
For all $\,x\in S\,$ the element $\,xx'$ is idempotent $\,(xx')^2=(xx'x)x'=xx'.$ Thus, being nonempty, $S\,$ has at least one idempotent. If $\,i\in S$ is idempotent, then $\,ix =ix\color{#0A0}{(ix)'}ix=ix\color{#C00}{(ix)'i}\:\!ix\,$ so, by uniqueness, $\color{#C00}{(ix)'i}=\color{#0A0}{(ix)'},$ hence $(ix)'=(ix)'(ix)''(ix)'=\color{#C00}{(ix)'i}x(ix)'=\color{#0A0}{(ix)'}x(ix)'$ so, by uniqueness, $x = (ix)''=ix.\,$ So every idempotent $\,i\,$ is a left identity and, by a symmetry, a right identity. Therefore, $S\,$ has at most one idempotent element. Combined with the previous result, this means that $S\,$ has exactly one idempotent element, denoted $\,e.\,$ We have shown that $\,e\,$ is an identity, and that $\,xx'=e\,$ for each $\,x\in S,$ hence $\,S\,$ is a group.
$(\Rightarrow)\,$ if $\,S\,$ is a group then $\,xyx=x\iff xy=1\iff y = x^{-1},\,$ so $\,y\,$ is unique.
$\ \bf\small QED$