The question is are these two pronounced the same.
If they are how would one know how to spell them.
This applies to any case of ウ vs 一.
胡椒, こしょう, コショウ and コショー refer to the same thing, and they are pronounced the same. The "standard" or "textbook" spelling is 胡椒 or こしょう, but コショウ and コショー are also widely used in the field of cooking.
Before explaining why, let's review the basic rule first. In general, traditional kango borrowed from Chinese more than hundreds of years ago are spelled in kanji, or sometimes hiragana, without long vowel markers. Recent loanwords are mostly from Western countries, and they are spelled using katakana and long vowel markers.
However, there are also some recent Chinese loanwords which came into use in Japan in the last 150 years or so. Many of them are names of Chinese food. They are usually written in katakana or kanji, and there can be more than one katakana spelling:
These can be seen as exceptional, "gray-area" cases between old kango and new loanwords. Such words are small in number, so you don't have to worry too much while you are a beginner.
Regarding 胡椒, it is an old kango (Wikipedia says it was first introduced from China to Japan circa 8th century), which is why it is normally spelled in kanji/hiragana. But since many Chinese food names are spelled using katakana and long vowel markers today, it started to be spelled as コショウ/コショー, too.