It does not work... I've tried for about 4 hours, but it still doesn't... Strangely enough, operator<< works in tests and when I compile my other programs with opencv I've built and installed. But it simply does not want to work inside this .cpp. I will continue the investigation.
Interestingly enough, after inspecting the other opencv code I did not find anyone, who'd try to print matrix via operator<< from the .cpp files in src/ folders.
And even more interesting, I did not find the implementation of operator<< for matrices (although it exists). Some people say, it's in modules/core/include/opencv2/core/operations.hpp, but I haven't seen it there.