Purpose of perfect codes Let $C$ be a $(n,M,d)_q$-code where $q$ is the cardinality of the code alphabet, $n$ is the codeword length and $d$ is the minimum Hamming distance of the code, i.e.,
$$
d=\min\{d(c,c'):c\neq c', c,c'\in C\}.
$$ It is said to be perfect if
$$
 M = \frac{q^n}{|B_{\lfloor \frac{d-1}{2} \rfloor}(c)|} \text{ for any } c \in C,
$$
where $B_r(x)$ is the Hamming ball of radius $r$ around the point
$x\in \{0,1,\ldots,q-1\}^n.$
I understand that a perfect code 'fills' the space without overlapping, so that every word  on the space $\{0,1,\ldots,q-1\}^n$ is at distance
less or equal to $\lfloor \frac{d-1}{2} \rfloor$ from exactly one codeword.
However, I don't understand why is this concept
introduced. What is the advantage of using $C$? What would happen if $C$ wasn't perfect.
 A: Firstly, it is an interesting geometric problem, given the scarcity of known perfect codes. They are basically the binary repetition code, the Golay codes, and the Hamming code. The general geometrical problem is that of packing, filling out the space with disjoint spheres. If there is a perfect packing this problem is solved in the most efficient way. See the linked question and answer for more details on perfect codes.
One application of Perfect codes is below:
Imagine that you want to do data compression. You can compress each possible vector of length  $n$ to the nearest codeword and transmit the index of that codeword.
This means that each possible source codeword in $\mathbb{F}_q^n$ has a unique compressed word associated with it, which makes the compression scheme particularly simple.
A: Football pools
An application of ternary perfect codes is football pools (in some countries called Toto). For example, the player predicts the outcome of 11 matches, each having three possibilities (team A wins, team B wins, draw).
Now how many bets (each consisting of the 11 predictions) are needed to ensure that there is one with 11 or 10 correct predictions? The answer 729 is given by the size of the perfect ternary Golay code.
This application might feel a bit farfetched, but historically this is how the ternary Golay code has been discovered originally. Golay in his 1949 article was not the first one! In fact, it was a guy called Juhani Virtakallio, who published a list of the codewords in the Finnish soccer magazine Veikkaaja in 1947. The list has been split into three parts, published in three separate issues.
State of knowledge
An addition to the (+1) answer of Kodlu:
The question for the perfect codes is essentially settled over alphabets of prime power size. However for other alphabets, the question is wide open. For example, to my knowledge is not decided if there exists a perfect senary (i.e. alphabet size 6) 1-error-correcting code of length 43 or of length 97.
Perfect codes are beautiful!
Also, let me affirm an aspect already hinted at by Kodlu: I think the first and foremost reason to be interested in perfect codes – at least as a mathematician – comes from a sense for esthetics. Being a perfect packing of Hamming balls in the Hamming space, they are just beautiful object. Think of the classical topic of tesselations. They are appealing and thus people have fun to investigate them. The situation for perfect codes is pretty much the same, with the little difference that their beauty comes in a more abstract setting, such that we cannot draw any pictures of them.
