The definition of homotopy equivalence in Munkre's book:

An exercise from the same book:
My problem with this:
If all functions are homotopic, doesn't that mean that all spaces are homotopically equivalent?! In fact we get $g\circ f\simeq i_X$ and $f\circ g\simeq i_Y$ whatever functions $f,g$ we choose, and looking at the definition this means that $X,Y$ are homotopically equivalent, whatever they are. Where am I mistaken?

The mistake is that the exercise shows that any two maps to $\mathbb{R^n}$, specifically, are homotopic. It's a property of $\mathbb{R^n}$. What it means for homotopy equivalence is that, when we're trying to show $X$ is homotopy equivalent to $\mathbb{R^n}$, it suffices to build a the homotopy between our maps on the "$X$" side, since we automatically get one on the $\mathbb{R^n}$ side. A corollary is that $\mathbb{R^m}$ is homotopy equivalent to $\mathbb{R^n}$ for all $m,n$, which is true.