$\require{AMScd}$
There is a retraction of $D^n\times I\twoheadrightarrow D^n×\{0\}\cup S^{n-1}×I$ defined via
$$r(x,t)=\begin{cases}
\left(\frac{2x}{2-t},\ 0\right) &\text{, if }t\le2(1-||x||) \\
\left(\frac x{||x||},2-\frac{2-t}{||x||}\right)&\text{, if }t\ge2(1-||x||)
\end{cases}$$ It is easy to prove that this map is well-defined and continuous and a retraction. Then $$d:D^n×I×I\to D^n×I\\ d(x,t,s)=sr(x,t)+(1-s)(x,t)$$
is a homotopy between the identity and $r$, so $r$ is a deformation retraction.
But then $(D^n×I)\cup_H X$ deformation retracts onto
$(D^n×\{0\}\cup S^{n-1}×I)\cup_H X=(D^n×\{0\})\cup_f X$
Note that a pushout square ($A,X$, and $B$ are arbitrary spaces)
\begin{CD}
A @>f>> B\\@ViVV @VV\tilde iV\\ X @>>\tilde f> X\cup_f B
\end{CD}
gives rise to a pushout square
\begin{CD}
A\times I @>f>> B \times I\\@ViVV @VV\tilde iV\\ X\times I @>>\tilde f> (X\cup_f B)\times I
\end{CD}
because the quotient map $q:X\sqcup B\to X\cup_f B$ induces a quotient map
$q\times 1:X\times I\sqcup B\times I\to(X\cup_f B)\times I$.
This means that a pair of homotopies $F_t:X→Y$, $G_t:B→Y$, such that $F_ti=G_t f$ for all $t\in I$, induces a homotopy
$H_t:X∪_f B→Y$
That's the reason why a deformation retraction on $D^n×I$ induces a deformation retraction on the pushout $(D^n×I)\cup_F X$
There is more general result: If $(X,A)$ is cofibered, then $X×I$ deformation retracts to $X×\{0\}\cup A×I$, so if $X$ is glued via two homotopic maps $f$ and $g$ to a space $B$, then $X\cup_f B$ and $X\cup_g B$ are homotopy equivalent.
The essence of the counterexample “X homotopy equivalent to Y but X not homeomorphic to Y” is the following. Consider a space $S$ which is homotopy equivalent to a point but is not a point, then attach $S$ to anoter space $R$, then you’ll get (with some few exceptions) a space $R'$ homotopy equivalent to $R$ but not homeomorphic to $R$. (In the counterexample this is the “fourth leg” attached to Y in order to obtain X.) The attaching procedure can be formalized by choosing two points, one in $S$ and one in $R$ and identifying them.
So a good source of understanding what kinds of properties of a space can be ignored by homotopy equivalences, is to focus on spaces that are homotopy equivalent to points but are not points. Such spaces can intuitively be though as spaces than retract on one of its points. For examples any cone is homotopy equivalent to a point. A cone of a space $X$ is the space obtained first by taking the product $X\times [0,1]$ and then by identifying $X\times\{1\}$ to a single point (the vertex of the cone). This provides a huge class of spaces which are homotopy equivalent to points. Note that Y is the cone of three points and X is the cone of four points. Both are homotopy equivalent to a point.
Properties that are invariant under homotopy equivalence, so that one can distinguish two not homotopy equivalent spaces by means of such properties, are for instance those coming from all homotopy groups (the fundamental group and other). This is the core of the theories of invariants in general.
Best Answer
Lens spaces are nice examples.
To quote from that article,