I would have said that he made a $25$% profit: he spent $\$40$ and got back $\$50$, for a profit of $\$10$, so his profit is $\frac{10}{40}=\frac14$, or $25$%, of his investment. The only way that I can see to get a profit of $20$% is to figure profit on the basis of the selling price: his profit is $\frac{10}{50}=\frac15$, or $20$%, of his selling price.
Your basic error is not realizing that you have to count all of his costs together: the effective cost to him of the saleable rug was $\$25+\$15=\$40$.