Homotopy equivalence of two different gluings of $B^n$ and an arbitrary space $X$
Solution 1:
There are two ways of trying to build homotopy equivalence maps between $X \cup_f B_n$ and $X \cup_g B_n$. One is to try to have $B_n$ stay fixed, and have things happen in $X$ instead. If you find a construction which works for an arbitrary space $S$, it would be one of this kind. The other is to try to have $X$ stay fixed, and have things happen in $B_n$ instead. Since we know what $B_n$ is and we don't know what $X$ is, it should be easier to do it this way.
So we want a continuous map $F : X \cup_f B_n \rightarrow X \cup_g B_n$, where $\forall x \in X, F(x) = x$. This means that we only want to find its restriction $F|_{B_n} : B_n \rightarrow X \cup_g B_n$, such that $\forall x \in S_{n-1}, F(x) = f(x)$
Now then, if you want to use the homotopy $h : S^{n-1} \times [0;1] \rightarrow X$ between $f$ and $g$, it makes sense to try to decompose $B^n$ and build something like this :
$$B_n \approx (S^{n-1} \times [0;1]) \cup B_n \rightarrow X \cup_g B_n$$
Finding such a decomposition and checking that the glueing works well is straightforward. Proving that the maps you obtain are an equivalence of homotopy, when you properly write down what their composition does, should be easy as well.
Solution 2:
You should be looking at the fact that $S^{n-1} \to B^n$ is a cofibration.
EDIT: This is a response to your below comment. There is a certain diagram that tells you what a cofibration is, it is annoying and ugly at first, but eventually it will make some amount of sense. The idea this diagram is supposed convey is that $A \to X$ (think of $A$ as a subspace of $X$) is a cofibration if we have a function out of $X$, say $f:X \to Y$, then once we have a homotopy of $f$ restricted to $A$ then we get a homotopy of "all" of $f$. There are many ways to think about cofibrations though, not all of them are easy to understand. Morally, a cofibration is a map $i: A \to X$ s.t. $X/i(A)$ behaves well in the eyes of homotopy theory, that is the homotopy type of $X/i(A)$ depends only on the homotopy class of $i$.
A couple of important points about cofibrations is that every map is homotopic to a cofibration, think about the mapping cylinder. Also, if you have the inclusion of a subspace $A$ into $X$ where $X$ is obtained from $A$ by attaching cells then that inclusion is a cofibration, this is an easy way of noticing that map in question is a cofibration. Now since it is a cofibration and since you have a homotopy then the quotients should be the same. That last sentence can be made precise, think about what the pushout is actually the quotient of and how you can fit your attaching map into that picture.