To perjure is to lie after taking an oath in a courtroom to tell the truth. If a witness to a crime deliberately gives false information in front of a judge, they perjure themselves.
It's possible to perjure yourself — or commit the crime of perjury — in a written statement or during any other legal transaction that requires you to swear you'll tell the truth. You only perjure yourself, however, if you tell a deliberate lie that affects the outcome of a trial or other legal decision. The Old French source of the word perjure is parjurer, "to break one's word," from the Latin root periurare, "to swear falsely."