I would be nice to have more insights as to the content of the test and the medium used.
If it is a complex algorithm (for instance I don't know, writing a compression method, an digital filter etc.) these kind of questions are better suited for pen&paper where the candidate will mostly spill out pseudo code, ideas and comments. As others said, in such a test I would not expect the candidate to write flawless code, but it will give me an idea as to whether he knows basic concepts of programming, possibly of a particular language, and most importantly if he knows how to think.
On the other hand, if you are given 45 minutes in front of a computer, I would expect it to be a very very simple task. This could be for instance writing a form where the user inputs some values that get serialized on disk. I would more be interested to know if the candidate is as fluent as he says with the tools provided. I would expect him to finish on time and evaluate the real quality of the code. Or if he had problems this would be a base of discussion as to what happened. Of course, in such a context I don't see why this test would not be "open books" with access to the Internet and any reference documentation needed.
Both tests are valid enough I think. But mixing them (doing a pen&paper test for code that is meant to compile flawlessly or doing a seated test with a complex algorithm) is just malicious! Maybe that is what your friend encountered.