  Let $(\mathcal{M},g)$ be a compact Riemannian manifold of dimension $N$,
$N\geq 2$. In this paper, we prove that there exists a family of domains
$(\Omega_\varepsilon)_{\varepsilon\in(0,\varepsilon_0)}$ and functions
$u_\varepsilon$ such that $ -\Delta_{g} u_\varepsilon=1 \quad \textrm{ in }
\Omega_\varepsilon, \quad u_\varepsilon=0 \quad\textrm{ on
}\partial\Omega_\varepsilon, \quad
  {g}(\nabla_{ {g}} {u_\varepsilon}, {\nu}_\varepsilon)=-\frac{\varepsilon}{N}
\quad \textrm{ on }\partial\Omega_\varepsilon, $ where $\nu_\varepsilon$ is the
unit outer normal of $\partial\Omega_\varepsilon$. The domains
$\Omega_\varepsilon$ are smooth perturbations of geodesic balls of radius
$\varepsilon$ centered at some point $p_0$. If, in addition, $p_0$ is a
non-degenerate critical point of the scalar curvature of $g$ then, the family
$(\partial\Omega_\varepsilon)_{\varepsilon\in(0,\varepsilon_0)}$ constitutes a
smooth foliation of a neighborhood of $p_0$. By considering a family of domains
$\Omega_\varepsilon$ in which the above overdetermined system is satisfied, we
also prove that if this family converges to some point $p_0$ in a suitable
sense as $\varepsilon\to 0$, then $p_0$ is a critical point of the scalar
curvature. A Taylor expansion of he energy rigidity for the torsion problem is
also given.
