There are some people who specifically don't want to know their baby's gender before birth.
Is there any halachic basis to this, or is it just superstition?
The Shailos Rav (by Rav Chaim Kanievsky), in 12:2, says one should not do it based off the Koheles Rabbah 11:5 and also can be seen in Medrash Rabbah Toldos 65:12 that says seven things are hidden from man and one of them is knowing the gender of a child in the womb .
I was in a shiur Rav Moshe Heinemann gave 3 years ago about halachos of pregnancy and childbirth, and he said that it is completely permitted and people just haven't gotten used to the idea yet.
I know of one posek who proved that this is perfectly fine, from the fact that many seforim cite traditional segulos to determine a fetus' gender. Obviously, then, there is nothing improper about knowing the gender beforehand. (One could argue that knowing with certainty is worse, but this seems like a distinction without a difference. And besides, even sonography is far from foolproof.)
It seems that it it Muttar, though some would say it isn't ideal. R' Avraham S. Avraham writes the following (Nishmas Avraham Vol 2, p109):
.. Incidentally, is a woman permitted to undergo sonography (ultrasound) to learn what the sex of the fetus is? The Midrash (Midrash Rabah, Bereishis 65:12) enumerates seven things whichare hidden from man, one of them being the sex of the fetus.
The Yefei To'ar gives two reasons for this: This knowledge may grieve the parents throughout the pregnancy if the sex of the baby is not of their choice; if they wish for a boy and discover that this is indeed the sex of the fetus, it will diminish their joy at the birth and the mother will not have the full reward for her labor pains.
On the other hand, the Gemara (Pesachim 54b) also enumerates the seven things that are hidden from man but the sex of the fetus is not one of them.
Rav Neuwirth shlita [zatzal] told me that it woould be preferable not to undergo sonography for this purpose.
It sounds like superstition. However, I know some don't want to know the baby's sex, so that they have a level of enjoyment after the long birthing process of finding out whether the baby is a boy or a girl. I am sure others might have other reasons. I don't know of any halachik basis.