A one point space $P$ is characterized by the property that there exists only one map $r^Y_P : Y \to P$, where $Y$ is arbitrary.
$X$ being contractible can be defined as being homotopy equivalent to a one point space $P = \{*\}$. This means that there exist maps $f : P \to X$ and $r : X \to P$ such that $r \circ f \simeq id_P$ and $f \circ r \simeq id_X$. Clearly $r = r^X_P$ and $r \circ f = r^P_P = id_Y$. Thus contractible means that $f \circ r^X_P \simeq id_X$ for some $f : P \to X$. This is equivalent to the existence of a homotopy $H : X \times I \to X$ such that $H_0 = id_X$ and $H_1$ is a constant map (here $H_t : X \to X, H_t(x) = H(x,t)$ for $t \in I$). This property is usually taken as the definition of contractible.
In fact, if $f \circ r^X_P \simeq id_X$, then there is a homotopy $H : X \times I \to X$ such that $H_0 = id_X$ and $H_1 = f \circ r^X_P$ which is a constant map. Conversely, given a homotopy $H$ as above, there exists $x_0 \in X$ such that $H_1(x) = x_0$ for all $x$. Now take $f : P \to X, f(*) = x_0$.
The fundamental group $\pi_1(X,x)$ can be represented as the set of pointed homotopy classes of pointed maps $u : (S^1,s_0) \to (X,x)$. If $X$ is contractible, then $u = id_X \circ u \simeq c \circ u$, where $c : X \to X$ is some constant map. Hence there exists a homotopy $G: S^1 \times I \to X$ such that $G_0 = u$ and $G_1$ is constant. The map $p : S^1 \times I \to D^2, p(x,t) = (1-t)x$, is a quotient map identifying $S^1 \times \{1\}$ to a point. Thus $G$ induces a map $\bar G : D^2 \to X$ such that $\bar G \circ p = G$. We have $\bar G(z) = G(z,0) =u(z)$ for $z \in S^1$.
Define $H : S^1 \times I \to X, H(z,t) = \bar G((1-t)z +ts_0)$. This is a well-defined continuous map (note that $\lVert (1-t)z +t \rVert \le (1-t)\lVert z \rVert + t \lVert s_0 \rVert = 1 - t + t = 1$). We have $H(z,0) = \bar G(z) = u(z), H(z,1) = \bar G(s_0) = u(s_0) = x$ and $H(s_0,t) = \bar G(s_0) = u(s_0) = x$. This shows that $u$ is pointed homotopic to the constant loop based at $x$.
See also Characterizing simply connected spaces.