As a Chinese from HK also, I can only say there is no evidence to show if it was first used as a racist term or not. And since Chinese does not really have a serious racist against foreign people, I don't think it's a racists term. UNLESS it's a term created around 1900AD, when the western countries "rent" all those lands in China. Note that there were occationally Arabic and white people working in high position of Chinese government several hundred to a thousand years ago, or even further before, and lots of foreign merchants living in the captial of China thousand years ago. We have had always welcome foreigners. So racists is really an non-issue in China unless you're talking about family matters.
Anyway. Gui () means ghost literally. But in Chinese language, it's very commonly used for its derived meanings. For example, when we describe someone's face colour is very white (even if the person is Chinese), we may describe their colour as "ghostly/white as ghost". Another common and interesting use of it is one that you often use only on people you're friendly with, and if they have some (negative) characteristics. Say, a person often forget stuff, you may call him "jian mang gui" (), with jian=easy, mang=forget, gui=... gui.
My take anyway, the most reasonable interpretation of "gui lo" is that white people are... white like ghosts, which is just a Chinese adjective. Chinese often describe things with comparison.
Another possible meaning could be to separate "human" (Chinese/East Asian) with other people. For this meaning, I need to stress that Chinese is a very subjective language. The ways that terms are used are often very subjective and has a "comparison". For example, Cantonese, when they say "Chinese", they are thinking about Cantonese, not about Mandarine. While a Beijing Chinese will likely think of their local dialect of Mandarine when talking about "Chinese". Now, when you talk about "human" (which is the same word as "people""person" in Chinese), we think of Chinese, or people who look similar. So, who are the others? If not human, then it's ghost. Chinese often use comparisons like that for fun, and over time, it forms terms that are commonly used in unoffical situations. So this is the second possibility that I can explain.
Again, unless it's a term formed when the westerners "rent" Chinese land, and place armies within our land (1900AD, that's not too long ago), I do not think it has its root of racist. Most likely a description or comparison of colour. AND, if the term is formed around 1900, then you can't reject the term even if it's racists because there is all reason for this racist term to form, that is, if it's the formation time.
Last note is that this term is not itself used as a racist term, but simply a casual term that points to white people, in Cantonese.