How can I prove the following:
If $X\supseteq K$ is contractible, then the quotient $X/K$ is homotopy equivalent to $X$?
Since $K$ is contractible, we have a homotopy $H:id_K\!\simeq\!c_{k_0}$ between the identity and the constant map $K\rightarrow\{k_0\}\!\subseteq\!K$. We are trying to find $f:X\rightarrow X/K$ and $g:X/K\rightarrow X$, such that $f\circ g\simeq id_{X/K}$ and $g\circ f\simeq id_X$.
Most probably, $f$ must be the quotient projection, but what about $g$? I thought about defining $g$ as $x\!\in\!X\setminus K\mapsto x$ and $k\!\in\!K\mapsto k_0$, but is this continuous? Probably not. What else then?
Theorem: The fundamental group of a finite graph $X$ is free.
Proof: if $T$ is the maximal (spanning) tree of $X$, and $E$ the set of edges ($1$-cells) not in $T$, then $T$ is contractible and $X$ is homotopy equivalent to $X/T$, which is (homeomorphic to) a bouquet of circles $\bigvee_{i=1}^{|E|}\mathbb{S}^1$. Therefore $\pi_1(X)\cong F_E$, the free group on the set $E$. $\blacksquare$

Are infinite trees also contractible?
The statement "if $K \subset X$ and $K$ is contractible, then $X/K$ is homotopy equivalent to $X$" does not hold in general. Specifically, you need to add the assumption that the pair $(X,K)$ has the homotopy extension property (see Hatcher's algebraic topology book, proposition 0.17). In particular, it works if $X$ is a CW complex and $K$ is a subcomplex.
For a simple counterexample, let $X$ be a circle, and let $K$ be the complement of a single point in $X$. Then $K$ is contractible, and $X/K$ is a non-Hausdorff space that is not homotopy equivalent to a circle.
Your proof that the fundamental group of a finite graph is free is correct, assuming that the graph is connected.
It is also true that any infinite tree is contractible, for the same reason that a finite tree is contractible (you can contract to any point using geodesic paths in the tree). Thus the fundamental group of an infinite graph is also free.