Electron leaving the atom From the photoelectric effect, we know that a photon can kick an electron outside the atom if it has the right amount of energy ($E_{\gamma} \geq W_0$).
On the other hand, pair production tells us that a photon can annihilate to form an electron and an anti-electron (positron).
I'm wondering, how do we know that a photon in the photoelectric effect will actually interact with the electron not annihilate to form a positron and an electron, then the positron will interact with the electron in the atom while the other electron will be the one moving around?
 A: In order to create an electron positron pair, a photon needs to have at least the energy of the mass of the two particles (511 keV * 2 = 1.02 MeV). The photons involved in the photoelectric effect are wayyy under 1 MeV (which would be in the gamma ray range).
Additionally, in order to create a e-/e+ pair, a photon has to interact with an atomic nucleus in order to conserve momentum. The positron would also quickly annihilate with another electron nearby, and you could easily detect the resultant two 511 keV gammas.
A: 
how do we know that a photon in the photoelectric effect will actually interact with the electron not annihilate to form a positron and an electron, then the positron will interact with the electron in the atom while the other electron will be the one moving around

In fact, we don't know. The electrons are indistinguishable. All electrons are made equal.
Both mechanisms you propose are plausible, as well as infinite number of other mechanisms. Well, the second one requires few of the particles to be virtual for low photon energies, but virtual particles are pretty much an established concept.
When one models some particle interaction, usually the most simple and probable mechanisms are counted first. Others are added only if simpler approximations don't look much like the experimental data.
Regarding a photoelectric effect, one can honestly skip everything related to pair-production and the result will still be "good enough" down to our best measurement abilities. Other things, like electrons in a crystal interacting each other are much, much, much more important in the photoelectric effect.
A: For a photon to give rise to a real (not virtual) electron/positron pair it must possess an energy of slightly greater than one million electron volts. This is a very energetic photon indeed. In comparison, the photon causing photoejection of an electron from an atom needs an energy of order ~an electron volt. This is typical of the photons that make up visible light.
A: The answer is, it does happen. Just at largely different energies. This picture (taken from this thesis, page 10) summarizes it quite nicely for scattering on Cu (Copper) atoms:

Photoelectric absorption is just the most relevant effect at low energies (as you can see from $10 - 10^3$ eV.
Let me summarize the other effects ($A$ stands for atom):

*

*Thomson scattering ($\gamma + e^- \to \gamma + e^-$): Photon is absorbed and emitted by an electron (also called elastic because the electron does not absorb energy) (also called Rayleigh scattering)

*Compton scattering ($\gamma + e^- \to \gamma + e^-$): Photon bounces off the electron and kicks it out of the electron as well (also called inelastic because the electron absorbs energy in the process)

*Photonuclear absorption ($\gamma + A \to A^*$): Honestly, I did not know about that one. The core seems to absorb the photon and become excited, but that only happens for specific energies, depending highly on the core.

*Pair Production ($\gamma + A \to e^+ e^- + A$): Finally, as you guessed, pair production plays a role at above 1 MeV. But not exactly as you state it. It is true that a photon cannot turn into an electron positron pair in the vacuum due to momentum conservation. However, close to an atom, the atom can absorb some of the momentum to achieve the conservation. But the electron and positron in this case will still be so fast the they just fly past the atom and the positron does not annihilate. Wikipedia shows the following Feynman diagram:

So, the answer to "what happens" is quite complicated, lots of different things happen depending on energy. Usually, you do not need the full picture (as for low energies). But it's good to have an overview.
Let me know if there are any errors in my answer!
A: This is actually a good question.
Because of conservation of momentum/energy, this cannot happen.
A single photon will not decay into an  electron-positron pair such that they would exist as two separate and independent particle states. One of the particles has to be "off-shell".
In other words the process of pair-production will involve a virtual particle,
and such particles do not exist for a time sufficient to allow for the process you have conceived.
A: Your question is a good one, because actually the answer is that both (photoelectric effect and pair production) can happen at the same time with one single photon causing both effects.
To have this you need:

*

*A photon initially with at least energy well above the 1Mev threshold. This photon can kick an electron out if and only if it can transfer more energy to the electron then the work function. The photon, contrary to popular belief, does not have to cease to exist. If it can transfer more energy to the electron then the work function, then the electron can be kicked off without absorbing the photon, and the photon does not cease to exist. The photon will just lose some energy (a little fraction of its total, around 10-10^3 eV), and change angle.


*the photon consequently still has energy above the pair production threshold (1 Mev), so it can and sometimes does transform into an electron positron pair. Please note that momentum has to be conserved, and the nucleus has to receive some recoil (momentum transfer), because in the center of mass frame, the electron positron pair's momentum is zero. This is impossible with a single photon, unless there is a nucleus close by. The nucleus will provide the requirement to obey momentum conservation.
A: Due to the gain of energy by the electron from outside (eg. in a discharge tube, when a high potential difference is created between the electrodes), the electron leaves the atom. In other words, it knocks out of the atom (because the gain of energy causes it to move to higher and higher energy levels according to BOHR'S MODEL OF ATOM. So after all, when its energy exceeds even the energy present in the electrons of the last shell, it gets knocked out. This causes the remaining atom to be positively charged with its mass almost equal to that of the atom itself since electrons have negligible mass and its charge equal to the number of electrons knocked out.
