Hi all. I think I may have a more accurate explanation to your interrogation, even if many of the things expressed above are true.
The character in Chinese texts brought to Japan through Korea at the beginning of the 4th century gradually came to be adopted by the Japanese for the writing of their own language, for which there was no native system of writing at the time.
Now, the Chinese characters were used phonetically to represent similar-sounding Japanese syllables--the meanings of the characters were more often than not ignored. In this way, one could represent phonetically any Japanese word. But because each Chinese character only corresponds to one syllable, it was necessary to use many characters to write multisyllabic words, which frequently involved a large number of brush strokes.
To simplify this bothersome process, instead of the full angular style of writing (kaisho 楷書; box writing), a simplified derivative writing style was devised (sousho 草書; cursive writing). It came to be believed that the sousho style suited the Japanese litterary notation better.
Toward the end of the
Nara period (710-794) and during the
Heian period (794-1185) the sousho style underwent further simplification, in which esthetics played some part, resulting in a stock of phonetic characters extensive enough to represent the entire phonetics of the Japanese language. This was the decisive step towards the establishment of a purely phonetic character system representing syllables. These simple syllable characters are known today as hiragana, but were then formerly referred to as "onna-de" or ladies' hand because they were first used by women of the Heian period in letters and literary writing, who were supposed to be ignorant of the exclusively male domain of Chinese learning, literature, and writing. However, over time, hiragana came to prevail as the dominant syllabary.
Katakana was developped a little later, but not much. While listening to lectures on the classics of Buddhism, students wrote in their texts notations on the pronounciatation of meanings of unfamiliar characters, and sometimes wrote commentaries between the lines of certain passages. This practice required the use of some sort of phonetic shorthand, which led in turn to the development of katakana.
Like hiragana, katakana is based on Chinese characters corresponding to particular syllables. However, unlike hiragana, which is a cursive simplification of kanji, the more angular katakana were developped taking only single components of kanjis of the kaisho style.
Because katakana was closely associated with science and learning, this syllabary was for a long time exclusively used by men.
The selection of hiragana and katakana in use today was laid down in 1900 in a decree for elementary schools. Some obsolete symbols such as we ゑ, ヱ, and wi ゐ, ヰ were dropped during reforms after WWII. As a result we have 46 kana recognized today.
As this brief (yeah, right!) explanation implies, katakana was strongly associated with science and learning, which is why it is found very often in botany and marine sciences, often replacing seldom used and/or overly cumbersome kanji, so no, not all katakana words are gairaigo.
As for the tendency of Japanese to katakanize foreign words, read the following thread.
NYT arcticle on English loan words | Japan Forum