Let us assume that $f\colon X\rightarrow Y$ is a map (there is no need for basepoints). It is to be shown that $f$ is a weak homotopy equivalence if and only if for every CW pair $(K,L)$, maps $\alpha\colon K\rightarrow Y$ and $\beta\colon L\rightarrow X$ such that $f\beta=\alpha$, there is a map $\alpha^{\prime}\colon K\rightarrow X$ such that $\alpha^{\prime}\vert_L=\beta$ and $f\alpha^{\prime}\simeq\alpha$ rel $L$. I leave it as an exercise to check that we may replace $Y$ by the mapping cylinder $M_f$ without changing either hypothesis, so that we can assume $f$ to be an inclusion WLOG. Then, $f$ is a weak equivalence if and only if $\pi_n(Y,X,x_0)=0$ for all $x_0\in X$ and $n\ge0$. I leave it as another exercise to check that this is the case if and only if the second property is satisfied for the CW pairs $(K,L)=(D^n,S^{n-1})$, $n\ge0$ (in the case $n=0$, we take $S^{-1}=\emptyset$). This equivalence can also be argued directly, but I find it more convenient to reduce to the case where $f$ is an inclusion anyway. It is thus clear that the second property is sufficient and it remains to argue that it is necessary.
Let me argue first that if $\alpha$ maps the $n$-skeleton of $K^n$ into $X$, then we can homotope it rel $K^n\cup L$ to a map taking the $(n+1)$-skeleton $K^{n+1}$ into $X$. Indeed, for an $(n+1)$-cell $\Phi\colon(D^{n+1},S^n)\rightarrow(K^{n+1},K^n)$ that is not in $L$, we can consider $\alpha\circ\Phi\colon(D^n,S^{n-1})\rightarrow(Y,X)$ and so the $(D^{n+1},S^n)$ case implies that we can homotope $\alpha\circ\Phi$ rel $S^{n-1}$ to a map into $X$. Together with the constant homotopy on $K^n\cup L$, these glue to a homotopy of $\alpha\vert_{K^{n+1}\cup L}$ rel $K^n\cup L$ to a map into $X$. Since the CW pair $(K,K^{n+1}\cup L)$ is cofibered, this extends to a homotopy of $\alpha$ rel $K^n\cup L$ to a map taking $K^{n+1}$ into $X$, as desired.
Now, we can start with the empty case $n=-1$, and homotope $\alpha$ rel $L$ to a map taking $K^0$ into $X$ in the $t$-interval $[0,1/2]$. Then, homotope the resulting map rel $K^0\cup L$ to a map taking $K^1$ into $X$ in the $t$-interval $[1/2,3/4]$. Continue this process inductively. Note that, for each $n\ge0$, the homotopies stay constant on $K^n$ after finitely many steps, so this extends to a well-defined homotopy rel $L$ whose value at $t=1$ is a map taking $K$ into $X$, as desired.
Two textbook references containing closely related results are Theorem 11.12. in Bredon's Topology and Geometry and Lemma 4.6. in Hatcher's Algebraic Topology.