There are indeed counterexamples to which Igor Belegradek gave reference. Here is aanother counterexample in the plane, perhaps the simplest there is: Let $X$ be an annulus with two disjoint arcsone arc attached to one of its boundary components and another arc attached to the other boundary component, and $Y$ - an an annulus with one arctwo disjoint arcs attached to the same one of its boundary components and another arc attached to the other boundary component.