diff --git a/src/main.rs b/src/main.rs
index 181edc7cc8a6d5d45814f06eb7c3847e4fe3223f..be0cfd3e7b374c2c30be8c263432313632defae1 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,7 +4,7 @@ use lol_html::{element, rewrite_str, text, RewriteStrSettings};
 use serde::{Deserialize, Serialize};
 use std::collections::HashMap;
 use std::fs::File;
-use std::io::Read;
+use std::io::{Read, Write};
 use std::sync::{Arc, Mutex};
 use thiserror::Error;
 
@@ -47,6 +47,8 @@ pub enum AppError {
 	InvalidOpfile(toml::de::Error),
 	#[error("Failed to match selector {0}")]
 	SelectorFailed(String),
+	#[error("Failed to apply edits {0}")]
+	EditsFailed(#[from] lol_html::errors::RewritingError),
 }
 
 pub type AppResult<T> = Result<T, AppError>;
@@ -132,7 +134,20 @@ fn main() -> AppResult<()> {
 		},
 	);
 
-	println!("{}", html.unwrap());
+	let write_path = if args.inline {
+		Some(args.input.clone())
+	} else {
+		args.output
+	};
+
+	if let Some(path) = write_path {
+		File::create(&path)
+			.map_err(|_| AppError::FailedToOpen(args.input.clone()))?
+			.write_all(html?.as_bytes())
+			.map_err(|_| AppError::FailedToRead(args.input.clone()))?;
+	} else {
+		println!("{}", html?);
+	}
 
 	Ok(())
 }