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.
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.