A writ of habeas corpus is a legal document that requires a person to be brought before a court to determine whether they are being lawfully detained. It is a safeguard of individual freedom because it prevents people from being unlawfully detained without due process of law. It also ensures that individuals are not held in custody without being charged with a crime or without being given a fair trial.