In superconducting qubit measurements, stray infrared photons lead to damping processes that degrade quantum coherence. In this Letter, we show that a thermal blocking filter made of multiwalled carbon nanotubes diluted in stainless steel powder can significantly improve the energy relaxation time, T1, and the pure dephasing time, , of a qubit. By using two independent measurement lines, with and without the filter, and switching between them in situ, we observe that with the filter there is an increase of more than 61% in T1 and 291% in . We characterize the filter, demonstrating that the scattering parameters remain stable down to 8 mK over a wide range of frequencies, spanning from 10 MHz to 50 GHz. We also show that the cutoff frequency of the filter is easily controlled by selecting the concentration of nanotubes.