In Deutsch–Jozsa algorithm, in order to encode the function into a unitary which can be used for the computation, we need to know the function beforehand. What is the use of finding whether a function is balanced or not if we already know what the function does?
You do not need to know the function beforehand, just some properties of it.
The idea is that you are assuming to know something about the function (it is either balanced or unbalanced), but lack some additional amount of information to completely characterise it. Deutsch-Jozsa algorithm shows that this additional amount of information, under some circumstances, can be efficiently recovered.